limsZkSample.choosePage = {

    getZkSampleParam: function () {
        let _this = this;
        return {
            type: 'grid',
            id: 'lims-zk-sample-choose-list-grid',
            url: limsZkSample.baseUrl + '/queries/raw',
            service: 'limsZkSampleServiceImpl',
            columns: limsZkSample.getZkSampleColumns(),
            readonly: true,
            page: true,
            onLoadSuccess: function (data) {
                if (Gikam.isNotEmpty(data)) {
                    this.activeRowByIndex(0)
                } else {
                    Gikam.getComp('lims-zk-sample-template-list-grid-choose').cleanData();
                    Gikam.getComp('lims-zk-sample-template-test-list-grid-choose').cleanData();
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('lims-zk-sample-template-list-grid-choose').done(function (grid) {
                    grid.refresh({
                        url: limsZkSample.templateUrl + '/queries',
                        requestData: {
                            zkSampleId_EQ: row.id,
                            minTestId_EQ: Gikam.isEmpty(_this.param.firstTestId) ? '' : _this.param.firstTestId,
                        }
                    })
                })
            },
        }
    },

    getZkSampleTemplateParam: function () {
        var _this = this, columns = limsZkSample.getZkSampleTemplateChooseColumns(), requestData = this.param;
        this.param.single ? columns.unshift({
            radio: true
        }) : columns.unshift({
            checkbox: true
        });
        return {
            type: 'grid',
            id: 'lims-zk-sample-template-list-grid-choose',
            service: 'limsZkSampleTemplateServiceImpl',
            columns: columns,
            // page : true,
            onLoadSuccess: function (data) {
                if (Gikam.isNotEmpty(data)) {
                    this.activeRowByIndex(0)
                } else {
                    Gikam.getComp('lims-zk-sample-template-test-list-grid-choose').cleanData();
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('lims-zk-sample-template-test-list-grid-choose').done(function (grid) {
                    grid.refresh({
                        url: limsZkSample.templateTestUrl + '/queries',
                        requestData: {
                            etId_EQ: row.spId
                        }
                    })
                })
            },
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.CONFIRM',
                icon: 'select',
                onClick: function () {
                    let selections = Gikam.getComp('lims-zk-sample-template-list-grid-choose').getSelections()
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM')
                        return
                    }
                    Gikam.getLastModal().close(selections);
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.CANCEL',
                icon: 'cancel',
                onClick: function () {
                    Gikam.getLastModal().close();
                }
            }]
        }
    },

    getZkSampleTemplateTestParam: function () {
        let _this = this;
        return {
            type: 'grid',
            id: 'lims-zk-sample-template-test-list-grid-choose',
            order: {orderNo: 'asc'},
            columns: limsZkSample.getZkSampleTemplateTestColumns(),
        }
    },

    create: function () {
        let _this = this;
        Gikam.create('layout', {
            id: 'lims-zk-sample-choose-list-layout',
            renderTo: Gikam.getLastModal().window.$dom,
            west: {
                width: '40%',
                title: 'T_LIMS_ZK_SAMPLE.SERVER_NAME',
                items: [this.getZkSampleParam()]
            },
            center: {
                items: [{
                    type: 'layout',
                    north: {
                        height: '40%',
                        title: 'T_LIMS_EXPERIMENTAL_TEMPLATE.SERVICE_NAME',
                        items: [this.getZkSampleTemplateParam()]
                    },
                    center: {
                        title: 'T_LIMS_EXPERIMENTAL_TEMPLATE_TEST.SERVICE_NAME',
                        items: [this.getZkSampleTemplateTestParam()]
                    }
                }]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
};
